﻿using HirelSeriesH.Entity;
using HirelSeriesH.Tools;
using MySql.Data.MySqlClient;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Windows.Forms;

namespace HirelSeriesH.Global 
{
    class Global
    {
        public static IWin32Window MainFrom;
        public static HomeForm HomeFrom;
        /// <summary>
        /// 用户身份角色
        /// </summary>
        private static string userRole = "Worker";
        /// <summary>
        /// 缺省用户名
        /// </summary>
        private static string userName = "default";
        /// <summary>
        /// 系统运行的时间长度
        /// </summary>
        private static double runTimeTotalMilliseconds;
        /// <summary>
        /// 硬件设备与通信串口的对应关系
        /// </summary>
        private static Dictionary<string, List<string>> deviceToPortDictionary = new Dictionary<string, List<string>>();
        /// <summary>
        /// 温箱通信串口
        /// </summary>
        private static SerialPort boxPort;
        /// <summary>
        /// 指示灯1通信串口
        /// </summary>
        private static SerialPort plcPort;
        /// <summary>
        /// 温箱定值模式是否正在运行
        /// </summary>
        private static bool valueBoxRunning = false;
        /// <summary>
        /// 温箱程序模式是否正在运行
        /// </summary>
        private static bool stepBoxRunning = false;
        /// <summary>
        /// 程序模式阶段参数设置实体
        /// </summary>
        private static List<StepOrder> stepOrderList;
        /// <summary>
        /// 温箱当前的设定温度（温度设定）
        /// </summary>
        private static string settingTemperatureStr = "0";
        /// <summary>
        /// 温箱当前的实时温度（当前温度）
        /// </summary>
        private static string currenTemperatureStr = "0";
        private static string currenTemperatureStr2 = "0";

        private static string currenShiDuStr = "0";

        /// <summary>
        /// 定时查询温箱当前的实时温度（当前温度）的时间间隔（毫秒）
        /// </summary>
        private static double currenTemperatureInterval = 2000;
        /// <summary>
        /// 电源升压等待时间
        /// </summary>
        private static int powerUpWaitTime = 0;
        /// <summary>
        /// 电源自动升压等待时间：1分钟
        /// </summary>
        private static int powerAutoUpWaitTime = 60000;
        /// <summary>
        /// 当前选择的老化板的电源的实时输出电压（电源电压）
        /// </summary>
        private static string powerVoltageStr = "";
        /// <summary>
        /// 老化板测试电压集合
        /// </summary>
        private static List<double> testVoltageList = new List<double>();
        /// <summary>
        /// 老化板实体集合
        /// </summary>
        private static List<Channel> channelList;

        private static List<Channel> channelListTemp = new List<Channel>();
        /// <summary>
        /// 当前选择的老化板
        /// </summary>
        private static Channel currentChannel;
        /// <summary>
        /// 当前选择老化板的通信地址
        /// </summary>
        private static int currentChannelAddress;
        /// <summary>
        /// 当前选择的老化板的剩余测试时间显示
        /// </summary>
        private static string lastTime;

        private static string execInfo;

        private static int stopTestFlag = 0;

        private static byte checkHighFlag = 255;

        /// <summary>
        /// 高压电源通信串口
        /// </summary>
        private static SerialPort highPowerPort;

        private static List<SerialPort> powerPortList = new List<SerialPort>();

        private static List<Power> powerList = new List<Power>();

        private static List<VGPower> powerVgList = new List<VGPower>();

        private static SerialPort upsPort;

        private static List<SerialPort> lowPowerPortList = new List<SerialPort>();

        //IRLable
        private static List<TextBox> labelArrayIR = new List<TextBox>();
        //VRLable
        private static List<TextBox> labelArrayVR = new List<TextBox>();
        //TJLable
        private static List<TextBox> labelArrayTJ = new List<TextBox>();
        //PWLable
        private static List<TextBox> labelArrayPW = new List<TextBox>();

        private static List<UIButton> buttons = new List<UIButton>();

        private static List<CommPort> channelPortList = new List<CommPort>();

        private static List<bool> flagButtons = new List<bool>();

        private static UITextBox powerVoltage;
        private static UITextBox powerCurr;
        private static TextBox powerVoltage2;
        private static TextBox powerVoltage3;
        private static TextBox powerVoltage4;

        private static ChannelManagementForm channelManagementForm;

        private static int channelPositionsCount = 4;

        /// <summary>
        /// 老化板通信串口
        /// </summary>
        private static CommPort channelPort;

        private static Channel powerChannel;

        private static CommPort channelPowerPort;

        private static List<PosJZ> posJzList = new List<PosJZ>();

        public static string CurrenHumidityStr = "";
        public static string CurrenHumidityStr2 = "";

        public static int iHASTCurrent = 1;//HAST号：1/2

        private static SerialPort nEmPort;

        public static EMcomm NEMcomm = null;

        private static SDTest sDTest;

        private static PtcBox ptcBox;

        private static List<decimal> dataIRList = new List<decimal>(32);

        private static List<decimal> dataVoltList = new List<decimal>(32);

        private static string syzq = "";

        private static string currenBoxStutas = "停止中";

        public static PLC_XINJE PLC_XINJE;

        public static IntPtr ChartWHandle1 = IntPtr.Zero;//实时曲线窗口句柄1
        //电源组字典
        public static Dictionary<string,PowerPack> powerPackList = new Dictionary<string, PowerPack>();

        public static Dictionary<string, List<string>> DeviceToPortDictionary { get => deviceToPortDictionary; set => deviceToPortDictionary = value; }
        public static string LastTime { get => lastTime; set => lastTime = value; }
        public static SerialPort BoxPort { get => boxPort; set => boxPort = value; }
        public static string PowerVoltageStr { get => powerVoltageStr; set => powerVoltageStr = value; }
        public static int CurrentChannelAddress { get => currentChannelAddress; set => currentChannelAddress = value; }
        public static double CurrenTemperatureInterval { get => currenTemperatureInterval; set => currenTemperatureInterval = value; }
        public static List<TextBox> LabelArrayIR { get => labelArrayIR; set => labelArrayIR = value; }
        public static List<TextBox> LabelArrayVR { get => labelArrayVR; set => labelArrayVR = value; }
        public static List<TextBox> LabelArrayTJ { get => labelArrayTJ; set => labelArrayTJ = value; }
        public static List<TextBox> LabelArrayPW { get => labelArrayPW; set => labelArrayPW = value; }
        public static int PowerUpWaitTime { get => powerUpWaitTime; set => powerUpWaitTime = value; }
        public static List<double> TestVoltageList { get => testVoltageList; set => testVoltageList = value; }
        public static int PowerAutoUpWaitTime { get => powerAutoUpWaitTime; set => powerAutoUpWaitTime = value; }
        public static string ExecInfo { get => execInfo; set => execInfo = value; }
        public static List<UIButton> Buttons { get => buttons; set => buttons = value; }
        public static int StopTestFlag { get => stopTestFlag; set => stopTestFlag = value; }
        public static double RunTimeTotalMilliseconds { get => runTimeTotalMilliseconds; set => runTimeTotalMilliseconds = value; }
        public static List<bool> FlagButtons { get => flagButtons; set => flagButtons = value; }
        public static string UserName { get => userName; set => userName = value; }
        public static string UserRole { get => userRole; set => userRole = value; }
        public static byte CheckHighFlag { get => checkHighFlag; set => checkHighFlag = value; }
        public static List<SerialPort> PowerPortList { get => powerPortList; set => powerPortList = value; }
        public static UITextBox PowerVoltage { get => powerVoltage; set => powerVoltage = value; }
        public static SerialPort PlcPort { get => plcPort; set => plcPort = value; }
        public static string SettingTemperatureStr { get => settingTemperatureStr; set => settingTemperatureStr = value; }
        public static string CurrenTemperatureStr { get => currenTemperatureStr; set => currenTemperatureStr = value; }
        public static bool ValueBoxRunning { get => valueBoxRunning; set => valueBoxRunning = value; }
        public static bool StepBoxRunning { get => stepBoxRunning; set => stepBoxRunning = value; }
        public static string CurrenShiDuStr { get => currenShiDuStr; set => currenShiDuStr = value; }
        internal static List<CommPort> ChannelPortList { get => channelPortList; set => channelPortList = value; }
        internal static List<Channel> ChannelListTemp { get => channelListTemp; set => channelListTemp = value; }
        internal static List<Power> PowerList { get => powerList; set => powerList = value; }
        internal static List<StepOrder> StepOrderList { get => stepOrderList; set => stepOrderList = value; }
        internal static List<Channel> ChannelList { get => channelList; set => channelList = value; }
        internal static Channel CurrentChannel { get => currentChannel; set => currentChannel = value; }
        internal static CommPort ChannelPort { get => channelPort; set => channelPort = value; }
        public static string CurrenTemperatureStr2 { get => currenTemperatureStr2; set => currenTemperatureStr2 = value; }
        internal static Channel PowerChannel { get => powerChannel; set => powerChannel = value; }
        internal static CommPort ChannelPowerPort { get => channelPowerPort; set => channelPowerPort = value; }
        public static List<PosJZ> PosJzList { get => posJzList; set => posJzList = value; }
        public static TextBox PowerVoltage2 { get => powerVoltage2; set => powerVoltage2 = value; }
        public static TextBox PowerVoltage3 { get => powerVoltage3; set => powerVoltage3 = value; }
        public static TextBox PowerVoltage4 { get => powerVoltage4; set => powerVoltage4 = value; }
        public static SerialPort HighPowerPort { get => highPowerPort; set => highPowerPort = value; }
        public static ChannelManagementForm ChannelManagementForm { get => channelManagementForm; set => channelManagementForm = value; }
        public static List<SerialPort> LowPowerPortList { get => lowPowerPortList; set => lowPowerPortList = value; }
        public static SerialPort NEmPort { get => nEmPort; set => nEmPort = value; }
        public static SDTest SDTest { get => sDTest; set => sDTest = value; }
        public static UITextBox PowerCurr { get => powerCurr; set => powerCurr = value; }
        public static SerialPort UpsPort { get => upsPort; set => upsPort = value; }
        internal static List<VGPower> PowerVgList { get => powerVgList; set => powerVgList = value; }
        internal static PtcBox PtcBox { get => ptcBox; set => ptcBox = value; }
        public static List<decimal> DataIRList { get => dataIRList; set => dataIRList = value; }
        public static string Syzq { get => syzq; set => syzq = value; }
        public static string CurrenBoxStutas { get => currenBoxStutas; set => currenBoxStutas = value; }
        public static int ChannelPositionsCount { get => channelPositionsCount; set => channelPositionsCount = value; }

        public static List<decimal> DataVoltList
        {
            get
            {
                return dataVoltList;
            }

            set
            {
                dataVoltList = value;
            }
        }
    }
}
